﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Dreaming_of_Space_2
{
    public class SpaceInvasion
    {
        public bool start_invasion = false;
        public int current_number_invasion_wave = 0; //номер волны нашествия
        public int max_number_invasion_wave = 20;
        //Корабли нашествия
        public int MaxUfoQuantity = 20;
        //public SpaceShip[] UfoInvasion = new SpaceShip[20];
        public SpaceShip[] UfoInvasion;
        public int UfoQuantity = 1; //колличество кораблей вышедших из подпространства
        public int CurrentInvasionQuantity = 1;

        public bool DrawInvasion(PaintEventArgs e, Planet Earth)
        {
            //прорисовка кораблей нашествия
            if (start_invasion == true)
                for (int i = 0; i < UfoQuantity; i++)
                {
                    if (UfoInvasion[i].armor >= 0)
                        if (UfoInvasion[i].CalculateTrace() == true)
                        {

                            UfoInvasion[i].Redraw_Ufo(e);
                            UfoInvasion[i].UfoOpenFire(e, Earth);
                        }
                }
            return true;
        }

        public bool CreateInvasionWave()
        {
            if (current_number_invasion_wave > max_number_invasion_wave)
            {
                MessageBox.Show("Космос наш", "Победа!",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }
            UfoQuantity = 1;
            start_invasion = false;
            CurrentInvasionQuantity = current_number_invasion_wave;

            for (int i = 0; i < MaxUfoQuantity; i++)
            {
                UfoInvasion[i].max_armor = 100 * current_number_invasion_wave;
                UfoInvasion[i].armor = UfoInvasion[i].max_armor;
                UfoInvasion[i].cargo = 100 * current_number_invasion_wave;
                UfoInvasion[i].fire_power = 1000 * current_number_invasion_wave;
                UfoInvasion[i].critical_damage = 10 + current_number_invasion_wave;
                UfoInvasion[i].SpaceTrace1.GetRandomTrace();
                UfoInvasion[i].InitTrace();

            }
            return true;
        }

        public bool CheckWaveIsDestroyed()
        {
            int count = 0;
            for (int i = 0; i < CurrentInvasionQuantity; i++)
            {
                if ((UfoInvasion[i].armor <= 0) || (UfoInvasion[i].CalculateTrace() == false))
                    count++;
                
            }
            if (count == CurrentInvasionQuantity) return true;
            else return false;
        }
    }
}
